package jin.si.com.service.impl;

import jin.si.com.dao.LianXiDao;

import jin.si.com.entity.*;
import jin.si.com.service.LianXiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @ClassName LianXiServiceImpl
 * @Author MT
 * @Date 2021/5/27 10:36
 **/

@Service
public class LianXiServiceImpl implements LianXiService {

    @Autowired
    public LianXiDao dao;


    //获取用户名字
    @Override
    public List<LangFang> getUserName() {
        List<LangFang> user = dao.getUserName();
        return user;
    }
    
    //旭日图
    @Override
    public List<Map<String,Object>>  getXuRiTu() {
        List<Map<String,Object>>  list = dao.getXuRiTu();
        for(Map<String,Object> map:list){
            int id = (int) map.get("code");
            List<Map<String, Object>> xuRiTuZi = getXuRiTuZi(id);
            map.put("children", xuRiTuZi);
        }
        return list;
    }



    public List<Map<String, Object>> getXuRiTuZi(int id) {
        List<Map<String, Object>> getXuRiTuZi = dao.getXuRiTuZi(id);
        if(getXuRiTuZi!=null) {
            for(Map<String, Object> list:getXuRiTuZi) {
                int id2 = (int) list.get("id");
                List<Map<String, Object>> child = getXuRiTuZi(id2);
                list.put("children", child);
            }
        }
        return getXuRiTuZi;
    }

    //数据库用户信息导出Excel
    @Override
    public List<Map<String,Object>> getUsers() {
        List<Map<String,Object>> list = dao.getUsers();
        return list;
    }

    @Override
    public User getUser2(int id) {
        User u = dao.getUser2(id);
        return u;
    }

    ///新闻
    @Override
    public List<News> getNews() {
        List<News> news = dao.getNews();
        return news;
    }

    //作品
    @Override
    public List<ZuoPin> getZuoPin() {
        List<ZuoPin> list = dao.getZuoPin();
        return list;
    }

    //作品2
    @Override
    public ZuoPin getZuoPin2(int id) {
        ZuoPin zp = dao.getZuoPin2(id);
        return zp;
    }

    //轮播图
    @Override
    public List<Carousel> getCarousels() {
        List<Carousel> carousels = dao.getCarousels();
        return carousels;
    }

    //视频
    @Override
    public List<Video> getVideos() {
        List<Video> list = dao.getVideos();
        return list;
    }

    //视频详情
    @Override
    public Video videoDatailApi(int id) {
        Video video = dao.videoDatailApi(id);
        return video;
    }


}
